package com.stellar.wechat.core.enums;

import lombok.Getter;

/**
 * @Author Jqcc
 * @Version 1.0
 * @Data 2025/3/30
 * @Description 微信错误码枚举
 */
@Getter
public enum WxErrorCode {

    SUCCESS(0, "成功"),

    INVALID_ACCESS_TOKEN(40001, "无效的access_token"),

    INVALID_OPENID(40003, "无效的openid"),

    INVALID_CODE(40029, "无效的code"),

    TOO_FREQUENT(45011, "API调用太频繁，请稍候再试"),

    FREQUENCY_LIMIT(45011, "API调用太频繁，请稍候再试"),

    /**
     * 风险等级详见用户安全解方案
     *
     * @see <a href="https://developers.weixin.qq.com/miniprogram/dev/framework/operation.html#%E7%94%A8%E6%88%B7%E5%AE%89%E5%85%A8%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88">
     */
    HIGH_RISK_USER(40226, "高风险等级用户，小程序登录拦截"),

    TEMPLATE_MSG_ERROR(43101, "模板消息发送失败"),

    SESSION_KEY_EXPIRED_OR_NOT_EXIST(87007, "会话密钥不存在或已过期"),

    TOKEN_GET_FAILED(50001, "获取AccessToken失败"),

    TOKEN_GET_NETWORK_ERROR(50001, "获取AccessToken网络异常"),

    SIGNATURE_ERROR(99999, "生成签名失败"),

    INVALID_SIGNATURE(87009, "无效的签名"),

    NETWORK_ERROR(10000, "网络通信异常"),

    INVALID_TEMPLATE_DATA(40037, "模板数据格式错误");


    private final int code;

    private final String desc;

    WxErrorCode(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static WxErrorCode getByCode(int code) {
        for (WxErrorCode errorCode : values()) {
            if (errorCode.code == code) {
                return errorCode;
            }
        }
        return null;
    }
}